﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using CommonWFLibrary;
using DTBuilderLib.VisualHierarchyClasses;
using DTBuilderLib;

namespace DeepTalkWF
{
    public partial class DeepZoomRender : LongRunningActivityBase
	{
		public DeepZoomRender()
		{
			InitializeComponent();
		}

        /// <summary>
        /// The input scene that we are going to render to a deep zoom image.
        /// </summary>
        public Visual Scene
        {
            get { return (Visual)GetValue(SceneProperty); }
            set { SetValue(SceneProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Scene.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SceneProperty =
            DependencyProperty.Register("Scene", typeof(Visual), typeof(DeepZoomRender), new PropertyMetadata(0));


        /// <summary>
        /// Output directory where the talk should be rendered to.
        /// </summary>
        public string TalkOutputDirectory
        {
            get { return (string)GetValue(TalkOutputDirectoryProperty); }
            set { SetValue(TalkOutputDirectoryProperty, value); }
        }

        // Using a DependencyProperty as the backing store for TalkOutputDirectory.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TalkOutputDirectoryProperty =
            DependencyProperty.Register("TalkOutputDirectory", typeof(string), typeof(DeepZoomRender), new PropertyMetadata(null));

        /// <summary>
        /// Get or set the image quality to be used when doing the render.
        /// </summary>
        public double ImageQuality
        {
            get { return (double)GetValue(ImageQualityProperty); }
            set { SetValue(ImageQualityProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ImageQuality.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ImageQualityProperty =
            DependencyProperty.Register("ImageQuality", typeof(double), typeof(DeepZoomRender), new PropertyMetadata(0.0));



        /// <summary>
        /// Args to be passed to the long running activity
        /// </summary>
        [Serializable]
        public class Args
        {
            public Visual _scene;
            public string _talkOutputDir;
            public double _imageQuality;
        }

        [LongRunningGatherArguments]
        public Args Gather()
        {
            Args a = new Args();
            a._scene = Scene;
            a._talkOutputDir = TalkOutputDirectory;
            a._imageQuality = ImageQuality;

            return a;
        }

        [LongRunningMethod]
        static public void Run(Args a)
        {
            DeepZoomBuilder bld = new DeepZoomBuilder();
            bld.BuildDirectory = a._talkOutputDir;
            bld.ImageQuality = a._imageQuality;
            bld.RenderVisual("meeting", a._scene);
        }
	}
}
